<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>通讯录</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="./layui/css/layui.css">
		<script src="./layui/layui.js"></script>
		<script type="text/javascript" src="js/global.js"></script>
	</head>

	<body>
		<form class="layui-form" action="">
			
			    <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input name="abname"  id="abname"  class="layui-input" type="text" placeholder="请输入姓名" autocomplete="off" lay-verify="title">
            </div>
        </div>

			<div class="layui-form-item">
				<label class="layui-form-label">性别</label>
				<div class="layui-input-block">
					<input type="radio" name="absex" value="男" title="男" checked="">
					<input type="radio" name="absex" value="女" title="女">
				</div>
			</div>

			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">手机号</label>
				<div class="layui-input-block">
					<input type="text" name="abtel" id="abtel" lay-verify="abtel" autocomplete="off" placeholder="请输入手机号" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" type="submit" lay-filter="formDemo" lay-submit="">立即提交</button>
					
				</div>
			</div>

		</form>

		<script>
			layui.use(['table', 'form', 'layer', 'laydate', 'layedit'], function() {
						var table = layui.table;
						var form = layui.form;
						var layer = layui.layer;
						var $ = layui.jquery;
						var layedit = layui.layedit
						//解决跨域
						$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
							options.xhrFields = {
								withCredentials: true
							}
						})

						

						//自定义验证规则
						form.verify({
							title: function(value,item) {
								if(value.length < 1) {
									return '姓名不能为空！！';
								}
							},
						
							abtel: [/^1[3|4|5|7|8]\d{9}$/, '手机必须11位，只能是数字！']

						});

						form.on('submit(formDemo)', function(data) {
						

								var d = data.field;
								var url = globalData.server + './Addressbook/add';
								$.post(url, d, function(res) {
									console.log(res);
									if(res.count > 0) {
										var index = parent.layer.getFrameIndex(window.name);
										parent.layer.close(index);
									}
								}, 'json');
								return false;
							});

						});
		</script>
	</body>

</html>